package com.se.hospitalmonitoring;

import java.util.ArrayList;

public class CallButtonInterface {
	private static CallButtonInterface instance = null;
	private final ArrayList<CallButtonListener> listeners = new ArrayList<CallButtonListener>();

	/**
	 * Private constructor
	 */
	private CallButtonInterface() {
	}

	/**
	 * Gets the singleton instance of this class
	 * 
	 * @return The singleton instance of this class
	 */
	public static CallButtonInterface getInstance() {
		if (instance == null)
			instance = new CallButtonInterface();
		return instance;
	}

	/**
	 * Called when the call button is pressed
	 */
	public void onCallButtonPressed() {
		for (CallButtonListener listener : listeners) {
			listener.onCallButtonPressed();
		}
	}

	/**
	 * Adds a listener that is notified when the call button is pressed
	 * 
	 * @param listener
	 *            The listener to add
	 */
	public void addListener(CallButtonListener listener) {
		listeners.add(listener);
	}

	/**
	 * Removes the given listener
	 * 
	 * @param listener
	 *            The listener to remove
	 */
	public void removeListener(CallButtonListener listener) {
		listeners.remove(listener);
	}

	/**
	 * A simple interface for being notified when the call button was pressed
	 */
	public static interface CallButtonListener {
		void onCallButtonPressed();
	}
}
